package com.example.javabasic.mianshi;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {


    public static void main(String[] args) {
        CountDownLatch latch = new CountDownLatch(1);

        new Thread(()->{
            System.out.println("zhixing ");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            latch.countDown();
        }).start();

        try {
            System.out.println("runnning");
            //等待调用  countDown() 方法,  每次调用这个方法 会让计数-1   当减到0 的时候 会 唤醒wait线程继续往下执行
            latch.await();
            System.out.println("over");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
